<template>
  <div class="mod-sys__flightlinesinfo">
    <el-form :inline="true" :model="state.dataForm" @keyup.enter="state.getDataList()">
      <el-form-item>
        <el-input v-model="state.dataForm.filename" placeholder="文件名称" clearable></el-input>
      </el-form-item>
      <el-form-item>
        <el-date-picker v-model="state.datetimerange" type="datetimerange" value-format="YYYY-MM-DD HH:mm:ss" :range-separator="$t('datePicker.range')" start-placeholder="起飞开始时间" end-placeholder="起飞结束时间"></el-date-picker>
      </el-form-item>
      <el-form-item>
        <el-input v-model="state.dataForm.aircraftid" placeholder="机号" clearable></el-input>
      </el-form-item>
      <el-form-item>
        <el-button @click="state.getDataList()">{{ $t("query") }}</el-button>
      </el-form-item>
      <el-form-item>
        <el-button type="info" @click="state.exportHandle()">{{ $t("export") }}</el-button>
      </el-form-item>
      <el-form-item>
        <el-button v-if="state.hasPermission('sys:flightlinesinfo:save')" type="primary" @click="addOrUpdateHandle()">{{ $t("add") }}</el-button>
      </el-form-item>
      <el-form-item>
        <el-button v-if="state.hasPermission('sys:flightlinesinfo:delete')" type="danger" @click="state.deleteHandle()">{{ $t("deleteBatch") }}</el-button>
      </el-form-item>
    </el-form>
    <el-table v-loading="state.dataListLoading" :data="state.dataList" border @selection-change="state.dataListSelectionChangeHandle" style="width: 100%">
      <el-table-column type="selection" header-align="center" align="center" width="50"></el-table-column>
      <el-table-column prop="takeofftime" width="160" label="起飞时间" header-align="center" align="center"></el-table-column>
      <el-table-column prop="landingtime" width="160" label="降落时间" header-align="center" align="center"></el-table-column>
      <el-table-column prop="flightno" label="航班号" header-align="center" align="center"></el-table-column>
      <el-table-column prop="aircraftid" label="机号" header-align="center" align="center"></el-table-column>
      <el-table-column prop="dep4code" label="起飞机场" header-align="center" align="center"></el-table-column>
      <el-table-column prop="arr4code" label="降落机场" header-align="center" align="center"></el-table-column>
      <!-- <el-table-column prop="flightid" label="航班ID" header-align="center" align="center"></el-table-column> -->
      <el-table-column prop="filename" width="188" label="文件名称" header-align="center" align="center"></el-table-column>
      <!-- <el-table-column prop="flightlineid" label="航班联线ID" header-align="center" align="center"></el-table-column> -->
      <el-table-column prop="startrownum" label="开始行号" header-align="center" align="center"></el-table-column>
      <el-table-column prop="endrownum" label="结束行号" header-align="center" align="center"></el-table-column>
      <el-table-column prop="deplong" label="起飞机场经度" header-align="center" align="center"></el-table-column>
      <el-table-column prop="deplat" label="起飞机场纬度" header-align="center" align="center"></el-table-column>
      <el-table-column prop="arrlong" label="到达机场经度" header-align="center" align="center"></el-table-column>
      <el-table-column prop="arrlat" label="到达机场纬度" header-align="center" align="center"></el-table-column>
      <!-- <el-table-column prop="isflight" label="是否航班（未用）" header-align="center" align="center">
        <template v-slot="scope">
          {{ state.getDictLabel("ISFLIGHT", scope.row.isflight) }}
        </template>
      </el-table-column> -->
      <el-table-column prop="matchstate" label="匹配状态" header-align="center" align="center"></el-table-column>
      <el-table-column prop="analystate" label="分析状态" header-align="center" align="center">
        <template v-slot="scope">
          {{ state.getDictLabel("ANALYSTATE", Number(scope.row.analystate)) }}
        </template>
      </el-table-column>
      <el-table-column prop="isvalid" label="有效标识" header-align="center" align="center"></el-table-column>
      <el-table-column prop="timestamp" width="160" label="创建时间" header-align="center" align="center"></el-table-column>
      <el-table-column prop="modifytime" width="160" label="更新时间" header-align="center" align="center"></el-table-column>
      <el-table-column prop="memo" width="200" label="备注" header-align="center" align="center"></el-table-column>
      <!-- 暂未使用 -->
      <el-table-column v-if="state.hasPermission('sys:flightlinesinfo:update') || state.hasPermission('sys:flightlinesinfo:delete')" 
        :label="$t('handle')" fixed="right" header-align="center" align="center" width="150">
        <template v-slot="scope">
          <el-button v-if="state.hasPermission('sys:flightlinesinfo:update')" type="primary" link @click="addOrUpdateHandle(scope.row.filename)">{{ $t("update") }}</el-button>
          <el-button v-if="state.hasPermission('sys:flightlinesinfo:delete')" type="primary" link @click="state.deleteHandle(scope.row.filename)">{{ $t("delete") }}</el-button>
        </template>
      </el-table-column>
    </el-table>
    <el-pagination :current-page="state.page" :page-sizes="[10, 20, 50, 100]" :page-size="state.limit" :total="state.total" layout="total, sizes, prev, pager, next, jumper" @size-change="state.pageSizeChangeHandle" @current-change="state.pageCurrentChangeHandle"> </el-pagination>
    <!-- 弹窗, 新增 / 修改 -->
    <add-or-update :key="addKey" ref="addOrUpdateRef" @refreshDataList="state.getDataList"></add-or-update>
  </div>
</template>

<script lang="ts" setup>
import useView from "@/hooks/useView";
import { nextTick, reactive, ref, toRefs, watch } from "vue";
import AddOrUpdate from "./flightlinesinfo-add-or-update.vue";

const view = reactive({
  getDataListURL: "/sys/flightlinesinfo/page",
  getDataListIsPage: true,
  exportURL: "/sys/flightlinesinfo/export",
  deleteURL: "/sys/flightlinesinfo",
  deleteIsBatch: true,
  datetimerange: null,
  dataForm: {
    filename: "",
    startDateTime: null as number | null,
    endDateTime: null as number | null,
    aircraftid: ""
  }
});

const state = reactive({ ...useView(view), ...toRefs(view) });

watch(
  () => state.datetimerange,
  (val: number[] | null) => {
    if (val === null) {
      state.dataForm.startDateTime = null;
      state.dataForm.endDateTime = null;
    } else {
      state.dataForm.startDateTime = val[0];
      state.dataForm.endDateTime = val[1];
    }
  }
);
watch(
  () => state.datetimerange,
  (val: number[] | null) => {
    if (val === null) {
      state.dataForm.startDateTime = null;
      state.dataForm.endDateTime = null;
    } else {
      state.dataForm.startDateTime = val[0];
      state.dataForm.endDateTime = val[1];
    }
  }
);

const addKey = ref(0);
const addOrUpdateRef = ref();
const addOrUpdateHandle = (filename?: number) => {
  addKey.value++;
  nextTick(() => {
    addOrUpdateRef.value.init(filename);
  });
};
</script>